<form method="post" action="{:Url('Goods/changeSort')}">
    <table class="table table-hover">
        <thead>
        <tr>
            <th class="hidden-xs">排序</th>
            <th>服务名称</th>
            <th class="hidden-xs">图片</th>
            <th class="hidden-xs">普通价格</th>
            <th class="hidden-xs">VIP价格</th>
            <th class="hidden-xs">分类</th>
            <th class="hidden-xs">销量</th>
            <th>上架</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {foreach name="goodsList" item="item"}
            <tr>
                <td class="hidden-xs">
                    <input type="hidden" name="goods_id[]" value="{$item.id}">
                    <input type="text" name="sort[]" class="form-control" style="width:60px;text-align:center" value="{$item.sort}">
                </td>
                <td>{$item.goods_name}</td>
                <td class="hidden-xs" style="position: relative;">
                    <img src="{$item.image}" alt="" class="goods-image" height="34px">
                    <div style="position:absolute;top:0;left:65px;display:none;border: 1px solid #ccc;"><img src="{$item.image}" alt="" style="max-width: 500px"></div>
                </td>
                <td class="hidden-xs">￥{$item.price}</td>
                <td class="hidden-xs">￥{$item.vip_price}</td>
                <td class="hidden-xs">{$item.cate_name}</td>
                <td class="hidden-xs">{$item.sales_sum}</td>
                <td>
                    {if condition="$item['is_on_sale'] eq 1"}
                        <a href="javascript:;" data-id="{$item.id}" data-field="is_on_sale" class="toggleStatus fa fa-check-circle text-info" style="font-size: 3rem;"></a>
                        {else/}
                        <a href="javascript:;" data-id="{$item.id}" data-field="is_on_sale" class="toggleStatus fa fa-times-circle text-danger" style="font-size: 3rem;"></a>
                    {/if}
                </td>
                <td>
                    <a href="#" class="btn btn-success btn-xs" target="_blank">查看</a>
                    <a href="{:Url('Goods/info',['id'=>$item['id']])}" class="btn btn-warning btn-xs">编辑</a>
                    <a href="{:Url('Goods/delete',['id'=>$item['id']])}" class="btn btn-danger btn-xs" onclick="return confirm('确认删除？');">删除</a>
                </td>
            </tr>
        {/foreach}
        </tbody>
    </table>
    <button type="submit" class="btn btn-warning">更新排序</button>
</form>

<div class="row page">
    <div class="col-sm-12 text-center">
        {$page}
    </div>
</div>

<script>
    $(".page a").click(function(){
        ajax_index($(this).data('p'));
    });
    $('.toggleStatus').click(function(){
        var obj = $(this);
        var id = obj.data('id');
        var field = obj.data('field');
        var status = obj.hasClass('fa-check-circle') ? 2 : 1; //sale:1切换到上架，2切换到下架
        $.ajax({
            url:"{:Url('Goods/toggleStatus')}",
            type:'post',
            data:{id:id,field:field,status:status},
            success:function(res){
                if(res > 0){
                    if(status == 1){
                        obj.attr('class','toggleStatus fa fa-check-circle text-info');
                    }else if(status == 2){
                        obj.attr('class','toggleStatus fa fa-times-circle text-danger');
                    }
                    layer.msg('操作成功');
                }else{
                    layer.msg('操作失败');
                }
            }
        })
    });
    $('.goods-image').mouseover(function(){
        $(this).next().show();
    }).mouseout(function(){
        $(this).next().hide();
    });
</script>